package com.wing.utils;

import com.alibaba.fastjson.JSONObject;
import com.wing.common.utils.DateUtils;
import com.wing.wechat.util.WechatUtil;
import com.wing.wechat.vo.*;
import org.apache.commons.lang.StringUtils;

import javax.net.ssl.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Https工具类
 *
 * @author xiayang
 */
public class HttpsUtils {

    /**
     * post请求-map
     *
     * @param url    请求URL
     * @param reqMap map参数
     * @return
     * @throws Exception
     */
    public static String httpsPostByMap(String url, Map<String, String> reqMap) throws Exception {
        HttpURLConnection con = null;
        String sendString = JSONObject.toJSONString(reqMap);
        try {
            URL u = new URL(url);
            con = (HttpURLConnection) u.openConnection();
            con.setRequestMethod("POST");
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setUseCaches(false);
            con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
            osw.write(sendString);
            osw.flush();
            osw.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("与服务器连接发生错误:" + e.getMessage());
        } finally {
            if (con != null) {
                con.disconnect();
            }
        }

        // 读取返回内容
        StringBuffer buffer = new StringBuffer();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
            String temp;
            while ((temp = br.readLine()) != null) {
                buffer.append(temp);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("从服务器获取数据失败:" + e.getMessage());
        }
        return buffer.toString();
    }

    /**
     * post请求-json
     *
     * @param url        请求url
     * @param paramsJson json参数
     * @return
     * @throws Exception
     */
    public static String httpsPostByJson(String url, String paramsJson){
        // 构建请求参数
        String result = "";
        PrintWriter out = null;
        BufferedReader in = null;
        try {
            trustAllHosts();
            URL url2 = new URL(url);
            HttpsURLConnection urlCon = (HttpsURLConnection) url2.openConnection();
            urlCon.setHostnameVerifier(DO_NOT_VERIFY);
            urlCon.setDoOutput(true);
            urlCon.setDoInput(true);
            urlCon.setRequestMethod("POST");
            urlCon.setRequestProperty("Content-type", "application/json;charset=UTF-8");
            urlCon.setConnectTimeout(5 * 1000);// 设置超时时间
            urlCon.setReadTimeout(5 * 1000);
            // 发送POST请求必须设置如下两行
            urlCon.setDoOutput(true);
            urlCon.setDoInput(true);
            // 获取URLConnection对象对应的输出流
            OutputStream os = urlCon.getOutputStream();
            // 参数是键值队 , 不以"?"开始
            os.write(paramsJson.getBytes());
            os.flush();
            // 发送请求参数
            // 定义BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), "UTF-8"));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            e.printStackTrace();
            // https(url,params);
            return null;
        } finally {// 使用finally块来关闭输出流、输入流
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            // urlCon.disconnect();
        }
        return result;
    }


    public static String httpsGet(String url) {
        // 创建SSLContext对象，并指定使用TLS协议
        SSLContext sslContext = null;
        try {
            sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, null, null);
            SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
            // 创建URL对象
            URL url1 = new URL(url);
            // 创建HttpsURLConnection对象
            HttpsURLConnection connection = (HttpsURLConnection) url1.openConnection();
            connection.setSSLSocketFactory(sslSocketFactory);
            // 设置请求方法为GET
            connection.setRequestMethod("GET");
            // 发送请求
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);
            // 读取响应数据
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            StringBuilder response = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();
            // 输出响应数据
            return response.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    };

    private static void trustAllHosts() {
        TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return new X509Certificate[]{};
            }

            public void checkClientTrusted(X509Certificate[] chain, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] chain, String authType) {
            }
        }};
        try {
            SSLContext sc = SSLContext.getInstance("TLS");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
//            //获取token
//            System.out.println("------------------获取TOKEN--------------------");
//            String tokenResult = httpsGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+ WechatUtil.ENTERPRISE_ID+"&corpsecret="+WechatUtil.ENTERPRISE_SECRET);
//            ResponseToken responseTokenVO = JSONObject.parseObject(tokenResult, ResponseToken.class);
//            System.out.println(responseTokenVO.getAccess_token());
//            //部门列表
//            System.out.println("------------------部门列表--------------------");
//            String departmentListResult = httpsGet("https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token="+responseTokenVO.getAccess_token());
//            ResponseDepartmentList departmentList = JSONObject.parseObject(departmentListResult, ResponseDepartmentList.class);
//            System.out.println(departmentList.getErrcode());
//            System.out.println(departmentList.getErrmsg());
//            for (ResponseDepartmentVO responseDepartment : departmentList.getDepartment()) {
//                System.out.println(responseDepartment.getId());
//                System.out.println(responseDepartment.getName());
//                System.out.println(responseDepartment.getName_en());
//            }
//            //部门详情
//            System.out.println("------------------部门详情--------------------");
//            String departmentDetailResult = httpsGet("https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token="+responseTokenVO.getAccess_token()+"&id="+1);
//            ResponseDepartmentDetail departmentDetail = JSONObject.parseObject(departmentDetailResult, ResponseDepartmentDetail.class);
//            System.out.println(departmentDetail.getDepartment().getId());
//            System.out.println(departmentDetail.getDepartment().getName());
//            System.out.println(departmentDetail.getDepartment().getName_en());
//            //创建部门
//            System.out.println("------------------创建部门--------------------");
//            String departmentTokenResult = httpsGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+ WechatUtil.ENTERPRISE_ID+"&corpsecret="+WechatUtil.ADDRESS_SECRET);
//            ResponseToken token = JSONObject.parseObject(departmentTokenResult, ResponseToken.class);
//            RequestCreateDepartment createDepartmentVO = new RequestCreateDepartment();
//            createDepartmentVO.setName("测试部门");
//            createDepartmentVO.setName_en("test_dept");
//            createDepartmentVO.setParentid(1);
//            System.out.println(JSONObject.toJSONString(createDepartmentVO));
//            String createDepartmentResult = httpsPostByJson("https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token="+token.getAccess_token(), JSONObject.toJSONString(createDepartmentVO));
//            ResponseCreateDepartment createDepartment = JSONObject.parseObject(createDepartmentResult, ResponseCreateDepartment.class);
//            System.out.println(createDepartment.getId());
//            System.out.println(createDepartment.getErrcode());
//            System.out.println(createDepartment.getErrmsg());

//            //成员ID列表
//            System.out.println("------------------成员ID列表--------------------");
//            String userTokenResult = httpsGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+ WechatUtil.ENTERPRISE_ID+"&corpsecret="+WechatUtil.ENTERPRISE_SECRET);
//            ResponseToken userToken = JSONObject.parseObject(userTokenResult, ResponseToken.class);
//            System.out.println(userToken.getAccess_token());
//            RequestListIdUser paramUser = new RequestListIdUser();
//            paramUser.setLimit(10000);
//            String listUserIdResult = httpsPostByJson("https://qyapi.weixin.qq.com/cgi-bin/user/list_id?access_token="+userToken.getAccess_token(), JSONObject.toJSONString(paramUser));
//            ResponseListIdUser listIdUser = JSONObject.parseObject(listUserIdResult, ResponseListIdUser.class);
//            System.out.println(listIdUser.getErrcode());
//            System.out.println(listIdUser.getErrmsg());

//            //创建成员
//            RequestCreateUser createUser = new RequestCreateUser();
//            createUser.setUserid("test11");
//            createUser.setName("测试11");
//            createUser.setAlias("test11");
//            createUser.setMobile("15921040811");
//            List<Integer> departmentList = new ArrayList<>();
//            departmentList.add(1);
//            createUser.setDepartment(departmentList);
//            createUser.setPosition("测试员11");
//            createUser.setGender(1);
//            createUser.setEmail("38116811@qq.com");
//            createUser.setAddress("测试地址11");
//            System.out.println(JSONObject.toJSONString(createUser));
//            String createUserResult = httpsPostByJson("https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token="+userToken.getAccess_token(), JSONObject.toJSONString(createUser));
//            System.out.println(createUserResult);

//            //读取成员
//            String getUserResult = httpsGet("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token="+userToken.getAccess_token()+"&userid=test");
//            System.out.println(getUserResult);

             //打开规则列表
//             String clockRuleListResult = httpsGet("https://qyapi.weixin.qq.com/cgi-bin/checkin/getcorpcheckinoption?access_token="+userToken.getAccess_token());
//             System.out.println(clockRuleListResult);

//             String content = "{\n" +
//                     "    \"errcode\": 0,\n" +
//                     "    \"errmsg\": \"ok\",\n" +
//                     "    \"group\": [{\n" +
//                     "        \"grouptype\": 1,\n" +
//                     "        \"groupid\": 69,\n" +
//                     "\t\t      \"open_sp_checkin\":true,\n" +
//                     "        \"checkindate\": [{\n" +
//                     "            \"workdays\": [\n" +
//                     "                1,\n" +
//                     "                2,\n" +
//                     "                3,\n" +
//                     "                4,\n" +
//                     "                5\n" +
//                     "            ],\n" +
//                     "            \"checkintime\": [{\n" +
//                     "                    \"work_sec\": 36000,\n" +
//                     "                    \"off_work_sec\": 43200,\n" +
//                     "                    \"remind_work_sec\": 35400,\n" +
//                     "                    \"remind_off_work_sec\": 43200\n" +
//                     "                },\n" +
//                     "                {\n" +
//                     "                    \"work_sec\": 50400,\n" +
//                     "                    \"off_work_sec\": 72000,\n" +
//                     "                    \"remind_work_sec\": 49800,\n" +
//                     "                    \"remind_off_work_sec\": 72000\n" +
//                     "                }\n" +
//                     "            ],\n" +
//                     "            \"noneed_offwork\": true,\n" +
//                     "            \"limit_aheadtime\": 10800000,\n" +
//                     "            \"flex_on_duty_time\": 0,\n" +
//                     "            \"flex_off_duty_time\": 0\n" +
//                     "        }],\n" +
//                     "        \"spe_workdays\": [{\n" +
//                     "            \"timestamp\": 1512144000,\n" +
//                     "            \"notes\": \"必须打卡的日期\",\n" +
//                     "            \"checkintime\": [{\n" +
//                     "                \"work_sec\": 32400,\n" +
//                     "                \"off_work_sec\": 61200,\n" +
//                     "                \"remind_work_sec\": 31800,\n" +
//                     "                \"remind_off_work_sec\": 61200\n" +
//                     "            }]\n" +
//                     "        }],\n" +
//                     "        \"spe_offdays\": [{\n" +
//                     "            \"timestamp\": 1512057600,\n" +
//                     "            \"notes\": \"不需要打卡的日期\",\n" +
//                     "            \"checkintime\": []\n" +
//                     "        }],\n" +
//                     "        \"sync_holidays\": true,\n" +
//                     "        \"groupname\": \"打卡规则1\",\n" +
//                     "        \"need_photo\": true,\n" +
//                     "        \"wifimac_infos\": [{\n" +
//                     "                \"wifiname\": \"Tencent-WiFi-1\",\n" +
//                     "                \"wifimac\": \"c0:7b:bc:37:f8:d3\"\n" +
//                     "            },\n" +
//                     "            {\n" +
//                     "                \"wifiname\": \"Tencent-WiFi-2\",\n" +
//                     "                \"wifimac\": \"70:10:5c:7d:f6:d5\"\n" +
//                     "            }\n" +
//                     "        ],\n" +
//                     "        \"note_can_use_local_pic\": false,\n" +
//                     "        \"allow_checkin_offworkday\": true,\n" +
//                     "        \"allow_apply_offworkday\": true,\n" +
//                     "        \"loc_infos\": [{\n" +
//                     "                \"lat\": 30547030,\n" +
//                     "                \"lng\": 104062890,\n" +
//                     "                \"loc_title\": \"腾讯成都大厦\",\n" +
//                     "                \"loc_detail\": \"四川省成都市武侯区高新南区天府三街\",\n" +
//                     "                \"distance\": 300\n" +
//                     "            },\n" +
//                     "            {\n" +
//                     "                \"lat\": 23097490,\n" +
//                     "                \"lng\": 113323750,\n" +
//                     "                \"loc_title\": \"T.I.T创意园\",\n" +
//                     "                \"loc_detail\": \"广东省广州市海珠区新港中路397号\",\n" +
//                     "                \"distance\": 300\n" +
//                     "            }\n" +
//                     "        ],\n" +
//                     "        \"range\": {\n" +
//                     "            \"party_id\": [],\n" +
//                     "            \"userid\": [\"icef\", \"LiJingZhong\"],\n" +
//                     "            \"tagid\": [2]\n" +
//                     "        },\n" +
//                     "        \"create_time\": 1606204343,\n" +
//                     "        \"white_users\": [\"canno\"],\n" +
//                     "        \"type\": 0,\n" +
//                     "        \"reporterinfo\": {\n" +
//                     "            \"reporters\": [{\n" +
//                     "                \"userid\": \"brant\"\n" +
//                     "            }],\n" +
//                     "            \"updatetime\": 1606305508\n" +
//                     "        },\n" +
//                     "        \"ot_info\": {\n" +
//                     "            \"type\": 2,\n" +
//                     "            \"allow_ot_workingday\": true,\n" +
//                     "            \"allow_ot_nonworkingday\": false,\n" +
//                     "            \"otcheckinfo\": {\n" +
//                     "                \"ot_workingday_time_start\": 1800,\n" +
//                     "                \"ot_workingday_time_min\": 1800,\n" +
//                     "                \"ot_workingday_time_max\": 14400,\n" +
//                     "                \"ot_nonworkingday_time_min\": 1800,\n" +
//                     "                \"ot_nonworkingday_time_max\": 14400,\n" +
//                     "                \"ot_workingday_restinfo\": {\n" +
//                     "                    \"type\": 2,\n" +
//                     "                    \"fix_time_rule\": {\n" +
//                     "                        \"fix_time_begin_sec\": 43200,\n" +
//                     "                        \"fix_time_end_sec\": 46800\n" +
//                     "                    },\n" +
//                     "                    \"cal_ottime_rule\": {\n" +
//                     "                        \"items\": [{\n" +
//                     "                            \"ot_time\": 18000,\n" +
//                     "                            \"rest_time\": 3600\n" +
//                     "                        }]\n" +
//                     "                    }\n" +
//                     "                },\n" +
//                     "                \"ot_nonworkingday_restinfo\": {\n" +
//                     "                    \"type\": 2,\n" +
//                     "                    \"fix_time_rule\": {\n" +
//                     "                        \"fix_time_begin_sec\": 43200,\n" +
//                     "                        \"fix_time_end_sec\": 46800\n" +
//                     "                    },\n" +
//                     "                    \"cal_ottime_rule\": {\n" +
//                     "                        \"items\": [{\n" +
//                     "                            \"ot_time\": 18000,\n" +
//                     "                            \"rest_time\": 3600\n" +
//                     "                        }]\n" +
//                     "                    }\n" +
//                     "                },\n" +
//                     "                \"ot_nonworkingday_spanday_time\": 0\n" +
//                     "            },\n" +
//                     "            \"uptime\": 1606275664,\n" +
//                     "            \"otapplyinfo\": {\n" +
//                     "                \"allow_ot_workingday\": true,\n" +
//                     "                \"allow_ot_nonworkingday\": true,\n" +
//                     "                \"uptime\": 1606275664,\n" +
//                     "                \"ot_workingday_restinfo\": {\n" +
//                     "                    \"type\": 2,\n" +
//                     "                    \"fix_time_rule\": {\n" +
//                     "                        \"fix_time_begin_sec\": 43200,\n" +
//                     "                        \"fix_time_end_sec\": 46800\n" +
//                     "                    },\n" +
//                     "                    \"cal_ottime_rule\": {\n" +
//                     "                        \"items\": [{\n" +
//                     "                            \"ot_time\": 18000,\n" +
//                     "                            \"rest_time\": 3600\n" +
//                     "                        }]\n" +
//                     "                    }\n" +
//                     "                },\n" +
//                     "                \"ot_nonworkingday_restinfo\": {\n" +
//                     "                    \"type\": 2,\n" +
//                     "                    \"fix_time_rule\": {\n" +
//                     "                        \"fix_time_begin_sec\": 43200,\n" +
//                     "                        \"fix_time_end_sec\": 46800\n" +
//                     "                    },\n" +
//                     "                    \"cal_ottime_rule\": {\n" +
//                     "                        \"items\": [{\n" +
//                     "                            \"ot_time\": 18000,\n" +
//                     "                            \"rest_time\": 3600\n" +
//                     "                        }]\n" +
//                     "                    }\n" +
//                     "                },\n" +
//                     "                \"ot_nonworkingday_spanday_time\": 0\n" +
//                     "            }\n" +
//                     "        },\n" +
//                     "        \"allow_apply_bk_cnt\": -1,\n" +
//                     "        \"option_out_range\": 0,\n" +
//                     "        \"create_userid\": \"gaogao\",\n" +
//                     "        \"use_face_detect\": false,\n" +
//                     "        \"allow_apply_bk_day_limit\": -1,\n" +
//                     "        \"update_userid\": \"sandy\",\n" +
//                     "        \"schedulelist\": [{\n" +
//                     "            \"schedule_id\": 221,\n" +
//                     "            \"schedule_name\": \"2\",\n" +
//                     "            \"time_section\": [{\n" +
//                     "                \"time_id\": 1,\n" +
//                     "                \"work_sec\": 32400,\n" +
//                     "                \"off_work_sec\": 61200,\n" +
//                     "                \"remind_work_sec\": 31800,\n" +
//                     "                \"remind_off_work_sec\": 61200,\n" +
//                     "                \"rest_begin_time\": 43200,\n" +
//                     "                \"rest_end_time\": 46800,\n" +
//                     "                \"allow_rest\": false\n" +
//                     "            }],\n" +
//                     "            \"limit_aheadtime\": 14400000,\n" +
//                     "            \"noneed_offwork\": false,\n" +
//                     "            \"limit_offtime\": 14400,\n" +
//                     "            \"flex_on_duty_time\": 0,\n" +
//                     "            \"flex_off_duty_time\": 0,\n" +
//                     "            \"allow_flex\": false,\n" +
//                     "            \"late_rule\": {\n" +
//                     "                \"allow_offwork_after_time\": false,\n" +
//                     "                \"timerules\": [{\n" +
//                     "                    \"offwork_after_time\": 3600,\n" +
//                     "                    \"onwork_flex_time\": 3600\n" +
//                     "                }]\n" +
//                     "            },\n" +
//                     "            \"max_allow_arrive_early\": 0,\n" +
//                     "            \"max_allow_arrive_late\": 0\n" +
//                     "        }],\n" +
//                     "        \"offwork_interval_time\": 300\n" +
//                     "    }]\n" +
//                     "}";
//
//            System.out.println("---------------企业所有打卡规则-----------------");
//            System.out.println("返回内容："+JSONObject.parseObject(content, ResponseCorpCheckinOption.class));
//            ResponseCorpCheckinOption corpCheckinOption = JSONObject.parseObject(content, ResponseCorpCheckinOption.class);
//            System.out.println("返回码："+ corpCheckinOption.getErrcode());
//            System.out.println("错误码描述："+ corpCheckinOption.getErrmsg());
//            for (ResponseCorpCheckinGroup responseCorpCheckinGroup : corpCheckinOption.getGroup()) {
//                System.out.println("打卡规则类型:"+responseCorpCheckinGroup.getGrouptype());
//                System.out.println("打卡规则id:"+responseCorpCheckinGroup.getGroupid());
//                System.out.println("打卡规则名称:"+responseCorpCheckinGroup.getGroupname());
//            }
//
//            String checkinData = "{\n" +
//                    "   \"errcode\":0,\n" +
//                    "   \"errmsg\":\"ok\",\n" +
//                    "   \"checkindata\": [{\n" +
//                    "\t\t\"userid\" : \"james\",\n" +
//                    "\t\t\"groupname\" : \"打卡一组\",         \n" +
//                    "\t\t\"checkin_type\" : \"上班打卡\",      \n" +
//                    "\t\t\"exception_type\" : \"地点异常\",   \n" +
//                    "\t\t\"checkin_time\" : 1492617610,  \n" +
//                    "\t\t\"location_title\" : \"依澜府\",    \n" +
//                    "\t\t\"location_detail\" : \"四川省成都市武侯区益州大道中段784号附近\",  \n" +
//                    "\t\t\"wifiname\" : \"办公一区\",         \n" +
//                    "\t\t\"notes\" : \"路上堵车，迟到了5分钟\",\n" +
//                    "\t\t\"wifimac\" : \"3c:46:d8:0c:7a:70\",\n" +
//                    "\t\t\"mediaids\":[\"WWCISP_G8PYgRaOVHjXWUWFqchpBqqqUpGj0OyR9z6WTwhnMZGCPHxyviVstiv_2fTG8YOJq8L8zJT2T2OvTebANV-2MQ\"],\n" +
//                    "\t\t\"sch_checkin_time\" : 1492617610,\n" +
//                    "\t\t\"groupid\" : 1,\n" +
//                    "\t\t\"schedule_id\" : 0,\n" +
//                    "\t\t\"timeline_id\" : 2\n" +
//                    "\t},{\n" +
//                    "\t\t\"userid\" : \"paul\",\n" +
//                    "\t\t\"groupname\" : \"打卡二组\",         \n" +
//                    "\t\t\"checkin_type\" : \"外出打卡\",      \n" +
//                    "\t\t\"exception_type\" : \"时间异常\",   \n" +
//                    "\t\t\"checkin_time\" : 1492617620,  \n" +
//                    "\t\t\"location_title\" : \"重庆出口加工区\",    \n" +
//                    "\t\t\"location_detail\" : \"重庆市渝北区金渝大道101号金渝大道\",  \n" +
//                    "\t\t\"wifiname\" : \"办公室二区\",         \n" +
//                    "\t\t\"notes\" : \"\",\n" +
//                    "\t\t\"wifimac\" : \"3c:46:d8:0c:7a:71\",\n" +
//                    "\t\t\"mediaids\":[\"WWCISP_G8PYgRaOVHjXWUWFqchpBqqqUpGj0OyR9z6WTwhnMZGCPHxyviVstiv_2fTG8YOJq8L8zJT2T2OvTebANV-2MQ\"],\n" +
//                    "\t\t\"lat\": 30547645,\n" +
//                    "        \"lng\": 104063236,\n" +
//                    "\t\t\"deviceid\":\"E5FA89F6-3926-4972-BE4F-4A7ACF4701E2\",\n" +
//                    "\t\t\"sch_checkin_time\" : 1492617610,\n" +
//                    "\t\t\"groupid\" : 2,\n" +
//                    "\t\t\"schedule_id\" : 3,\n" +
//                    "\t\t\"timeline_id\" : 1\n" +
//                    "\t}]\n" +
//                    "}";
//            System.out.println("---------------打卡记录数据-----------------");
//            System.out.println("返回内容："+JSONObject.parseObject(checkinData, ResponseCheckinData.class));
//            ResponseCheckinData responseCheckinData = JSONObject.parseObject(checkinData, ResponseCheckinData.class);
//            System.out.println("返回码："+ responseCheckinData.getErrcode());
//            System.out.println("错误码描述："+ responseCheckinData.getErrmsg());
//            for (ResponseCheckinDataDetail checkinDataDetail : responseCheckinData.getCheckindata()) {
//                System.out.println("用户id:"+checkinDataDetail.getUserid());
//                System.out.println("打卡规则名称:"+checkinDataDetail.getGroupname());
//                System.out.println("打卡类型:"+checkinDataDetail.getCheckin_type());
//            }
//
//            System.out.println("---------------打卡月报数据-----------------");
//            String checkinMonthData = "{\n" +
//                    "    \"errcode\": 0,\n" +
//                    "    \"errmsg\": \"ok\",\n" +
//                    "    \"datas\": [\n" +
//                    "        {\n" +
//                    "            \"base_info\": {\n" +
//                    "                \"record_type\": 1,\n" +
//                    "                \"name\": \"张三\",\n" +
//                    "                \"name_ex\": \"Three Zhang\",\n" +
//                    "                \"departs_name\": \"有家企业/realempty;有家企业;有家企业/部门A4\",\n" +
//                    "                \"rule_info\": {\n" +
//                    "                    \"groupid\": 10,\n" +
//                    "                    \"groupname\": \"规则测试\"\n" +
//                    "                },\n" +
//                    "                \"acctid\": \"ZhangSan\"\n" +
//                    "            },\n" +
//                    "            \"summary_info\":{\n" +
//                    "                \"except_days\":3,\n" +
//                    "                \"regular_work_sec\":31,\n" +
//                    "                \"standard_work_sec\":29040,\n" +
//                    "                \"work_days\":3\n" +
//                    "            },\n" +
//                    "            \"exception_infos\":[\n" +
//                    "                {\n" +
//                    "                    \"count\":2,\n" +
//                    "                    \"duration\":28920,\n" +
//                    "                    \"exception\":4\n" +
//                    "                },\n" +
//                    "                {\n" +
//                    "                    \"count\":1,\n" +
//                    "                    \"duration\":60,\n" +
//                    "                    \"exception\":1\n" +
//                    "                },\n" +
//                    "                {\n" +
//                    "                    \"count\":1,\n" +
//                    "                    \"duration\":60,\n" +
//                    "                    \"exception\":2\n" +
//                    "                }\n" +
//                    "            ],\n" +
//                    "            \"sp_items\":[\n" +
//                    "                {\n" +
//                    "                    \"count\":0,\n" +
//                    "                    \"duration\":0,\n" +
//                    "                    \"time_type\":0,\n" +
//                    "                    \"type\":100,\n" +
//                    "                    \"vacation_id\":0,\n" +
//                    "\t\t\t\t\t\"name\": \"外勤次数\"\n" +
//                    "                },\n" +
//                    "                {\n" +
//                    "                    \"count\":1,\n" +
//                    "                    \"duration\":0,\n" +
//                    "                    \"time_type\":0,\n" +
//                    "                    \"type\":1,\n" +
//                    "                    \"vacation_id\":2,\n" +
//                    "\t\t\t\t\t\"name\": \"年假\"\n" +
//                    "                }\n" +
//                    "            ],\n" +
//                    "            \"overwork_info\": {\n" +
//                    "\t\t\t\t\"workday_over_sec\": 54000,\n" +
//                    "\t\t\t\t\"restdays_over_sec\": 205560,\n" +
//                    "\t\t\t\t\"workdays_over_as_vacation\": 0,\n" +
//                    "\t\t\t\t\"workdays_over_as_money\": 54000,\n" +
//                    "\t\t\t\t\"restdays_over_as_vacation\": 0,\n" +
//                    "\t\t\t\t\"restdays_over_as_money\": 172800,\n" +
//                    "\t\t\t\t\"holidays_over_as_vacation\": 0,\n" +
//                    "\t\t\t\t\"holidays_over_as_money\": 0\n" +
//                    "\t\t\t}\n" +
//                    "        }\n" +
//                    "    ]\n" +
//                    "}";
//            System.out.println("返回内容："+JSONObject.parseObject(checkinMonthData, ResponseCheckinMonthData.class));
//            ResponseCheckinMonthData responseCheckinMonthData = JSONObject.parseObject(checkinMonthData, ResponseCheckinMonthData.class);
//            System.out.println("返回码："+ responseCheckinMonthData.getErrcode());
//            System.out.println("错误码描述："+ responseCheckinMonthData.getErrmsg());
//            for (ResponseCheckinMonthDataDetail checkinMonthDataDetail : responseCheckinMonthData.getDatas()) {
//                System.out.println("打卡人员姓名:"+checkinMonthDataDetail.getBase_info().getName());
//                System.out.println("应打卡天数:"+checkinMonthDataDetail.getSummary_info().getWork_days());
//                System.out.println("异常次数:"+checkinMonthDataDetail.getException_infos().get(0).getCount());
//                System.out.println("假勤类型:"+checkinMonthDataDetail.getSp_items().get(0).getType());
//                System.out.println("工作日加班时长:"+checkinMonthDataDetail.getOverwork_info().getWorkday_over_sec());
//            }
//
//            System.out.println("---------------打卡人员排班信息-----------------");
//            String checkinSchduleList = "{\n" +
//                    "    \"schedule_list\":[\n" +
//                    "        {\n" +
//                    "            \"userid\":\"james\",\n" +
//                    "            \"yearmonth\":202011,\n" +
//                    "            \"groupid\":11,\n" +
//                    "\t\t\t\"groupname\":\"排班\",\n" +
//                    "            \"schedule\":{\n" +
//                    "                \"scheduleList\":[\n" +
//                    "                    {\n" +
//                    "                        \"day\":25,\n" +
//                    "                        \"schedule_info\":{\n" +
//                    "                            \"schedule_id\":229,\n" +
//                    "                            \"schedule_name\":\"早班\",\n" +
//                    "                            \"time_section\":[\n" +
//                    "                                {\n" +
//                    "                                    \"id\":1,\n" +
//                    "                                    \"work_sec\":32400,\n" +
//                    "                                    \"off_work_sec\":43200,\n" +
//                    "                                    \"remind_work_sec\":32400,                                         \"remind_off_work_sec\":43200\n" +
//                    "                                }\n" +
//                    "                            ]\n" +
//                    "                        }\n" +
//                    "                    },\n" +
//                    "                    {\n" +
//                    "                        \"day\":26,\n" +
//                    "                        \"schedule_info\":{\n" +
//                    "                            \"schedule_id\":171,\n" +
//                    "                            \"schedule_name\":\"晚班\",\n" +
//                    "                            \"time_section\":[\n" +
//                    "                                {\n" +
//                    "                                    \"id\":2,\n" +
//                    "                                    \"work_sec\":64800,\n" +
//                    "                                    \"off_work_sec\":79200,\n" +
//                    "                                    \"remind_work_sec\":64800,\n" +
//                    "                                    \"remind_off_work_sec\":79200\n" +
//                    "                                }\n" +
//                    "                            ]\n" +
//                    "                        }\n" +
//                    "                    },\n" +
//                    "                    {\n" +
//                    "                        \"day\":30,\n" +
//                    "                        \"schedule_info\":{\n" +
//                    "                            \"schedule_id\":0,\n" +
//                    "                            \"schedule_name\":\"休息\",\n" +
//                    "                            \"time_section\":[\n" +
//                    "\n" +
//                    "                            ]\n" +
//                    "                        }\n" +
//                    "                    }\n" +
//                    "                ]\n" +
//                    "            }\n" +
//                    "        }\n" +
//                    "    ],\n" +
//                    "    \"errcode\":0,\n" +
//                    "    \"errmsg\":\"ok\"\n" +
//                    "}\n";
//            System.out.println("返回内容："+JSONObject.parseObject(checkinSchduleList, ResponseCheckinSchedule.class));
//            ResponseCheckinSchedule responseCheckinSchedule = JSONObject.parseObject(checkinSchduleList, ResponseCheckinSchedule.class);
//            System.out.println("返回码："+ responseCheckinSchedule.getErrcode());
//            System.out.println("错误码描述："+ responseCheckinSchedule.getErrmsg());
//            for (ResponseCheckinScheduleList responseCheckinScheduleList : responseCheckinSchedule.getSchedule_list()) {
//                System.out.println("打卡人员userid:"+responseCheckinScheduleList.getUserid());
//                System.out.println("排班表月份:"+responseCheckinScheduleList.getYearmonth());
//                System.out.println("打卡规则名:"+responseCheckinScheduleList.getGroupname());
//                System.out.println("班次名称:"+responseCheckinScheduleList.getSchedule().getScheduleList().get(0).getSchedule_info().getSchedule_name());
//                System.out.println("上班时间:"+responseCheckinScheduleList.getSchedule().getScheduleList().get(0).getSchedule_info().getTime_section().get(0).getWork_sec());
//            }

            System.out.println("---------------------------打卡人员排班列表------------------------------------");
            System.out.println("------------------获取TOKEN--------------------");
            String tokenResult = httpsGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+ WechatUtil.ENTERPRISE_ID+"&corpsecret="+WechatUtil.ENTERPRISE_SECRET);
            ResponseToken responseTokenVO = JSONObject.parseObject(tokenResult, ResponseToken.class);
            System.out.println("Token:"+responseTokenVO.getAccess_token());
            RequestCheckinSchedule checkinSchedule = new RequestCheckinSchedule();
            checkinSchedule.setStarttime(DateUtils.timeStampToUint32(DateUtils.getStartOfMonth(new Date()).getTime()));
            checkinSchedule.setEndtime(DateUtils.timeStampToUint32(DateUtils.getEndOfMonth(new Date()).getTime()));
            List<String> userList = new ArrayList<>();
            userList.add("zhangsan");
            checkinSchedule.setUseridlist(userList);
            String result = httpsPostByJson(WechatUtil.GET_CHECKIN_SCHEDULE_LIST_URL.replace("ACCESS_TOKEN",responseTokenVO.getAccess_token()),JSONObject.toJSONString(checkinSchedule));
            System.out.println("返回结果："+ result);
            ResponseCheckinSchedule responseCheckinSchedule11 = JSONObject.parseObject(result, ResponseCheckinSchedule.class);
            System.out.println("返回码："+ responseCheckinSchedule11.getErrcode());
            System.out.println("错误码描述："+ responseCheckinSchedule11.getErrmsg());
            for (ResponseCheckinScheduleList responseCheckinScheduleList : responseCheckinSchedule11.getSchedule_list()) {
                System.out.println("打卡人员userid:"+responseCheckinScheduleList.getUserid());
                System.out.println("排班表月份:"+responseCheckinScheduleList.getYearmonth());
                System.out.println("打卡规则名:"+responseCheckinScheduleList.getGroupname());
                System.out.println("班次名称:"+responseCheckinScheduleList.getSchedule().getScheduleList().get(0).getSchedule_info().getSchedule_name());
                System.out.println("上班时间:"+responseCheckinScheduleList.getSchedule().getScheduleList().get(0).getSchedule_info().getTime_section().get(0).getWork_sec());
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
